#include "stdafx.h"
#include "myformatstring.h"

myFormatString::myFormatString(void)
{
}

myFormatString::~myFormatString(void)
{
}

int myFormatString::FormatString(CString stringline, CString stringsep)
{
	int     num_script_parts=	0;
	int		pos				=	0;
	CString s1='"';
	stringline.Replace(s1," "+s1+" ");
	CString res				=	stringline.Tokenize(stringsep,pos);
	while(res != "")
	{
		tempparts[num_script_parts]	=	res;
		num_script_parts++;
		res	=stringline.Tokenize(stringsep,pos);
	}
	int commentstart	=0;
	int tempcommentpos	=0;
	int commentpos		=0;
	numofparts			=0;
	for(int i=0;i<num_script_parts;i++)
	{
		if((commentstart	==	0)&&(tempparts[i].Find('"')>=0))
		{
			parts[numofparts]	=	tempparts[i];
			commentstart		=	1;
		}
		else
		{
			if((commentstart	==	1)&&(tempparts[i].Find('"')<0))
			{
				parts[numofparts] += " "+tempparts[i];
			}
			else
			{
				if((commentstart	==	1)&&(tempparts[i].Find('"')>=0))
				{
					parts[numofparts] += " "+tempparts[i];
					numofparts++;
					commentstart	=	0;
				}
				else
				{
					parts[numofparts] = tempparts[i];
					numofparts++;
				}

			}
		}
	}
	return 0;
}
